package com.bw.servlet;

import com.bw.dao.PhoneDao;
import com.bw.pojo.Phone;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/***************************
 FileAction:

 CreateTime:2022-05-11 14:29
 Author:Aaking-aline
 ****************************/
@WebServlet("/SelectServlet2")
public class SelectServlet2 extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

	@SneakyThrows
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String phone_name = request.getParameter("phone_name");
		String phone_model = request.getParameter("phone_model");

		List<Phone> list = new PhoneDao().selectPhoneByPhoneNameAndPhoneModel(phone_name, phone_model);

		request.setAttribute("list",list);

		List<String> phone_names = new PhoneDao().selectAllPhoneName();
		List<String> phone_models = new PhoneDao().selectAllPhoneModel();

		int pageNum = new PhoneDao().selectPageNum(); // 查询总数据行数一共有多少页

		request.setAttribute("phone_names",phone_names);
		request.setAttribute("phone_models",phone_models);
		request.setAttribute("pageNum",pageNum);


		request.getRequestDispatcher("message.jsp").forward(request,response);
	}
}
